import os
from utils import ReadXml


def main(path):
    RemoveList = []

    for root, dirs, files in os.walk(SrcDir):
        for file in files:
            if file[-1] == 'l':
                Locations = ReadXml(root + "\\" + file)
                if len(Locations) == 0:
                    RemoveList.append(file)
                    os.remove(root + "\\" + file)
                    os.remove(root + "\\" + file[:-3] + "jpg")
    if len(RemoveList) == 0:
        print("All xml have label")
    else:
        print("Remove %d xmls and jpgs" % len(RemoveList))
        print(RemoveList)


if __name__ == '__main__':
    SrcDir = r"I:\ImgOutput\TrainData\BigLabel"
    main(SrcDir)
